﻿@{
    ViewData["Title"] = "角色编辑";
    Layout = "~/Views/Shared/_LayuiEdit.cshtml";
}
<link href="~/layuiadmin/layui/extend/eleTree.css" rel="stylesheet" />
<form class="layui-form" lay-filter="form" onsubmit="return false;">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="save">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <button type="Button" class="layui-btn layui-btn-danger" onclick="closePage()">关闭</button>
        </div>
    </div>
    <input type="hidden" name="Id" />
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input type="text" name="RoleName" class="layui-input" lay-verify="required" placeholder="" />
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <div class="layui-card">
                <div class="layui-card-header">权限菜单选择</div>
                <div class="layui-card-body">
                    @*<div id="menuTree" class="demo-tree-more"></div>*@
                    <div class="eleTree ele1"></div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    layui.config({
        base: '../layuiadmin/layui/extend/' //静态资源所在路径
    });
    var el1;
    addLayuiApp("eleTree");
    addLayuiUseEvent(function () {
        var roleId;
        if (formModel) roleId = formModel.Id; else roleId = "";
        var eleTree = layui.eleTree;
        el1 = eleTree.render({
            elem: '.ele1',
            url: "/api/apirole/GetMenuTree",
            where: { "Id": roleId },  //post 参数 等
            contentType: "application/json",
            method: "post",
            showCheckbox: true,
            renderAfterExpand: true,
            expandOnClickNode: true,
            defaultExpandAll: true,
            //checkStrictly: true,
            //autoExpandParent:false,
            request: {
                name: "title",
                key: "id",
                children: "children",
                checked: "checked",
                disabled: "disabled"
                //isLeaf: "spread"
            },
            done: function (res) {
               
            }
            //defaultCheckedKeys: [23]
        });
    });
    beforeSaveHandler = function (data) {        
        var selectedAllIds = [];
        var nodes = el1.getChecked(false, true);
        $.each(nodes, function (index, val) {
            selectedAllIds.push(val.id);
        });
        data["Menus"] = selectedAllIds.join(',');

        //var selectedIds = [];
        //var nodes2 = el1.getChecked(true, false);
        //$.each(nodes2, function (index, val) {
        //    selectedIds.push(val.id);
        //});        
        //data["MenusSet"] = selectedIds.join(',');
        return data;
    }
</script>
@*<script src="~/js/role/edit.js"></script>*@